package com.yun.zf.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.zf.common.admin.dto.house.HouseDetailAdminDto;
import com.yun.zf.common.admin.model.house.HouseListMo;
import com.yun.zf.common.app.domain.ZfHouseBasic;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 房源表 Mapper 接口
 * </p>
 *
 * @author cj
 * @since 2021-01-29
 */
@Mapper
public interface ZfHouseBasicMapper extends BaseMapper<ZfHouseBasic> {


    @Select("<script>" +
            " SELECT hb.id, hb.region_name, hb.street_name ,hb.community,hb.record_name,hb.modified_time,hb.city_code,hb.province_code , hd.bedrooms,hd.living_room,hd.toilet,hd.area,hd.hoped_price ,hd.floor_tag,hd.total_floor,hd.direction,hd.house_number,hd.price_unit" +
            " from zf_house_basic hb  LEFT JOIN  zf_house_detail hd on  hb.id=hd.basic_id  WHERE  hb.id in " +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')' > " +
            "  #{item} " +
            "  </foreach>" +
            "and  hb.city_code=#{cityCode} and hb.province_code=#{provCode}  " +
            "</script>")
    public List<HouseListMo> getRecommondHouse(Long provCode, Long cityCode, List<Long> ids);

    @Select("<script>" +
            " SELECT hb.id,hb.province_code,hb.city_code,hb.province_name,hb.city_name,hb.community,hb.community_id,hb.section,hb.unit,hb.room,hb.type,hb.region_name,hb.street_name,hb.`status`,hb.source ,hb.record_name,hb.push_time, \n" +
            "   hd.hoped_price,hd.area,hd.bedrooms,hd.living_room,hd.toilet,hd.total_floor,hd.floor_tag,hd.direction,hd.is_elevator,hd.price_unit,hd.title,hd.average_price,i.tags,i.check_in_time,i.equipment,i.fixtures,i.recommend_reason\n" +
            "  from zf_house_basic hb LEFT JOIN \n" +
            "  zf_house_detail hd ON hb.id= hd.basic_id\n" +
            " LEFT JOIN zf_house_info i on hb.id=i.basic_id" +
            " WHERE hb.id=#{id} and hb.city_code=#{cityCode} and hb.province_code=#{provinceCode}" +
            "</script>")
    HouseDetailAdminDto getBasicInfo(Long id, Long provinceCode, Long cityCode);

    @Select("<script>" +
            "SELECT hb.id, hb.region_name, hb.street_name ,hb.community,hb.record_name,hb.modified_time,hb.city_code,hb.province_code , hd.bedrooms,hd.living_room,hd.toilet,hd.area,hd.hoped_price ,hd.floor_tag,hd.total_floor,hd.direction,hd.house_number,hd.price_unit ,i.tags " +
            " from zf_house_basic hb  LEFT JOIN  zf_house_detail hd on  hb.id=hd.basic_id   LEFT JOIN zf_house_info i  ON hb.id=i.basic_id    WHERE hb.id!=#{houseId} and hb.type=#{type} AND hb.`status`='published' and hb.community_id=#{communityId}  and hb.city_code=#{cityCode} and hb.province_code=#{provCode} " +
            "</script>")
    public List<HouseListMo> getHouseListByCommunity(@Param("provCode") Long provCode, @Param("cityCode") Long cityCode, @Param("communityId") Long communityId, @Param("type") int type, Long houseId , Page<HouseListMo> page);


}
